package com.clkj.aimin.dao.user;

import com.clkj.aimin.pojo.user.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author yawang
 * @create 2024/04/02 17:10:55
 **/
@Repository
public interface UserMapper extends Mapper<User> {
    @Insert("insert into t_cl_user values (#{userName},#{userTel},#{userSex},#{doctorId},#{familyId},#{openId},#{birth},#{cardCode},#{userType},#{userImg}," +
            "#{taskScore},#{parentId},#{isVip},#{parentCode},#{vipTime},#{helperId},#{registNum},#{loveNum},#{unionId},#{password})")
    @Options(useGeneratedKeys = true, keyProperty = "userId", keyColumn = "user_id")
    void addUser(User user);

//    @Select("select u1.*,u2.user_name  ,d.doctor_name as doctorName from t_cl_user u1 " +
//            "left join  t_cl_doctor d  on u1.doctor_id = d.doctor_id " +
//            "left join t_cl_user u2 on u1.helper_id = u2.user_id " +
//            "where u1.user_id=#{userId}")
//    User getUserInfoById(Integer userId);

    @Select("select a.*,b.user_name as helperName,c.user_name as doctorName  from t_cl_user a " +
            "left join t_cl_user b on a.helper_id = b.user_id " +
            "left join t_cl_user c on a.doctor_id = c.user_id " +
            "where a.user_id=#{userId} ")
    User getGeren(Integer userId);

    @Select("select a.*,b.user_name as helperName,c.user_name as doctorName  from t_cl_user a " +
            "left join t_cl_user b on a.helper_id = b.user_id " +
            "left join t_cl_user c on a.doctor_id = c.user_id " +
            "where a.parent_code=#{parentCode} ")
    List<User> listFamilyUsers(String parentCode);

    @Update("<script>" +
            "update t_cl_user " +
            "<if test='type==0'> set regist_num +=1 </if>" +
            "<if test='type==1'> set love_num +=1 </if> " +
            "where user_id = #{userId} " +
            "</script>")
    void returnNum(Integer userId,Integer type);
}
